<?php
/**
 * 内容页
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: ViewController.class.php v1.0 2014-06-13 17:27:03 $
 */
namespace Home\Controller;
class ViewController extends CommonController{
    private $TypeModel;
    private $ContentModel;
    private $Content;
    private $ArcID;
    public function _initialize() {
        parent::_initialize();
        $this->TypeModel = D("Contype");
        $this->ContentModel = D("Content");
        $aid = I("get.aid", 0, "intval");
        if($aid <= 0){
            $this->error("对不起，你输入的参数有误！");
        }
        $this->ArcID = $aid;
        $this->Content = $this->ContentModel->getContent($aid);
        if($this->Content['status'] != 1){
            $this->error("该文档正在审核中！");
        }
        $this->TypeId = $this->Content['typeid'];
        $this->ContentModel->TypeInfos = $this->TypeInfos = $this->TypeModel->getTypeInfos($this->TypeId);
        //var_dump($this->TypeInfos);die;
        if(!isArrayAndNotEmpty($this->TypeInfos)){
            $this->error("对不起，你输入的参数有误！", "javascript:;");
        }
        
        $data = array();
        
        $data['TypeModel'] = $this->TypeModel;
        $data['ContentModel'] = $this->ContentModel;
        /*----SEO信息-----*/
        //当前位置
        $data['position'] = $this->GetPositionLink(true);
        //网页标题
        $data['title'] = $this->Content['title'];
        
        //SEO标题
        $data['seotitle'] = $this->TypeInfos['seotitle'];
        
        //栏目关键字没有就用网站默认关键字
        if($this->TypeInfos['keywords'] != ""){
            $data['keywords'] = $this->TypeInfos['keywords'];
        }
        //栏目描述没有就用网站默认描述
        if($this->TypeInfos['description'] != ""){
            $data['description'] = $this->TypeInfos['description'];
        }
        /*----SEO信息 END-----*/
        /*----文档信息-----*/
        //文档ID
        $data['aid'] = $this->Content['id'];
        //简短标题
        $data['shorttitle'] = $this->Content['shorttitle'];
        //发布时间
        $data['pubdate'] = $this->Content['pubdate'];
        //点击量
        $data['click'] = $this->Content['click'];
        //信息来源
        $data['source'] = $this->Content['source'];
        //作者
        $data['writer'] = $this->Content['writer'];
        //文档内容
        $data['body'] = htmlspecialchars_decode($this->Content['body']);
        /*----文档信息 END-----*/
        /*----栏目信息----*/
        //栏目名称
        $data['typename'] = $this->TypeInfos['typename'];
        //栏目ID
        $data['typeid'] = $this->TypeInfos['id'];
        //上级栏目ID
        $data['reid'] = $this->TypeInfos['reid'];
        //顶级栏目ID
        $data['topid'] = $this->TypeInfos['topid'];
        //当前栏目链接
        $data['typeurl'] = $this->TypeInfos['typeurl'];
        /*----栏目信息 END----*/
        
        $this->assign($data);
    }
    
    public function index() {
        if(preg_match("#j#", $this->Content['flag']) && $this->Content['redirecturl'] != ''){
            if(!C('CFG_JUMP_ONCE')){
                redirect($this->Content['redirecturl'], 3, "现在正在转向：".$this->Content['title']."，请稍候...<br/><br/>\r\n转向内容简介:".$this->Content['description']);
            }else{
                redirect($this->Content['redirecturl']);
            }
            exit();
        }
        
        if(!empty($this->Content['templet'])){
            $tempfile = T($this->Content['templet']);
        }else{
            $tempfile = T($this->TypeInfos["temparticle"]);
        }
        if(!file_exists($tempfile)){
            $tempfile = T("article_default");
        }
        $this->assign("field", $this->Content);
        //$this->buildHtml($this->Content['id'], HTML_PATH . '/news/', $tempfile);
        $this->display($tempfile);
    }
}
